<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta name="exporter-version" content="Evernote Mac 6.7.1 (453574)"/><meta name="author" content="冯鸿杰"/><meta name="created" content="2016-04-11 12:05:30 +0000"/><meta name="source" content="desktop.mac"/><meta name="updated" content="2016-07-06 12:06:46 +0000"/><title>iOS扩展开发攻略(一) - Share Extension</title></head><body>
<h1>iOS扩展开发攻略(一) - Share Extension</h1>
<div><font face="Helvetica">Demo源码：</font><a href="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/ShareExtensionDemo.zip">ShareExtensionDemo.zip</a></div>
<div><span style="font-family: Helvetica;"><br/></span></div>
<div><span style="font-size: 24px;"><b><font face="Helvetica">1. 什么是扩展？</font></b></span></div>
<div><span style="font-size: 11px;"><span style="font-family: 'PingFang SC';"><br/></span></span></div>
<div><span style="color: rgb(51, 51, 51);">扩展（ Extension ）是 iOS 8 中引入的一个非常重要的新特性。扩展让 app 之间的数据交互成为可能。用户可以在 app 中使用其他应用提供的功能，而无需离开当前的应用。在 iOS 8 系统之前，每一个 app 在物理上都是彼此独立的， app 之间不能互访彼此的私有数据。而在引入扩展之后，其他 app 可以与扩展进行数据交换。基于安全和性能的考虑，每一个扩展运行在一个单独的进程中，它拥有自己的 bundle ， bundle 后缀名是.appex 。扩展 bundle 必须包含在一个普通应用的 bundle 的内部。</span></div>
<div><span style="color: rgb(51, 51, 51);"><br/></span></div>
<div><span style="color: rgb(51, 51, 51);">iOS 8 系统有 6 个支持扩展的系统区域，分别是 Today 、 Share 、 Action 、 Photo Editing 、 Storage Provider 、 Custom keyboard 。支持扩展的系统区域也被称为扩展点。</span></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><b><span style="font-size: 18px;"><span style="color: rgb(51, 51, 51);">Today Widget</span></span></b></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><span style="color: rgb(51, 51, 51);">对于赛事比分，股票、天气、快递这类需要实时获取的信息，可以在通知中心的Today 视图中创建一个 Today 扩展实现。 Today 扩展又称为 Widget 。</span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/EAF80C61-9F0D-4AC3-8D93-13E0BDBAB48F.png" height="422" width="231"/></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><b><span style="font-size: 18px;"><span style="color: rgb(51, 51, 51);">Share</span></span></b></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><span style="color: rgb(51, 51, 51);">在 iOS 8 之前，用户只有 Facebook,Twitter 等有限的几个分享选项可以选择。如果希望将内容分享到 Pinterest ，开发者则需要一些额外的努力。在 iOS 8 中，开发者可以创建自定义的分享选项。</span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/F78F136F-285E-429B-BEA0-A52CB5C0627E.png" height="423" width="214"/></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><b><span style="font-size: 18px;"><span style="color: rgb(51, 51, 51);">Action</span></span></b></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><span style="color: rgb(51, 51, 51);">action 在所有支持的扩展点中扩展性最强的一个。它可以实现转换另一个 app 上下文中的内容。苹果在 WWDC 大会上演示了一个 Bing 翻译动作扩展，它可以将在 Safari 中选中的文本翻译成不同的语言。</span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/DF0C6219-77BC-4693-B4BE-E0051A69BAA3.png" height="423" width="212"/></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><b><span style="font-size: 18px;"><span style="color: rgb(51, 51, 51);">Photo Editing</span></span></b></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><span style="color: rgb(51, 51, 51);">在 iOS 8 之前，如果你想为你的照片添加一个特殊的滤镜，你需要进入第三方 app 中，这个过程是相当繁琐的。在 iOS 8 中，你可以直接在 Photos 中使用第三方 app ，如 Instagram ， VSCO cam 、 Aviary 提供的 Photo Editing 扩展完成对图片的编辑，而无需离开当前的 app 。</span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/85F7ED1A-9B92-4B72-AF7A-B636B716EF83.png" height="418" width="218"/></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><b><span style="font-size: 18px;"><span style="color: rgb(51, 51, 51);">Storage Provider</span></span></b></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><span style="color: rgb(51, 51, 51);">Storage Provider 让跨多个文件存储服务之间的管理变得更简单。类似 Dropbox 、 Google Drive 等存储提供商通过在 iOS 8 中提供一个 Storage Provider 扩展， app 直接可以使用这些扩展检索和存储文件而不再需要创建不必要的拷贝。</span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/0DBC9CA8-94E6-4925-8C68-38FD89F8CB46.png" height="430" width="214"/></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><b><span style="font-size: 18px;"><span style="color: rgb(51, 51, 51);">Custom Keyboard</span></span></b></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><span style="color: rgb(51, 51, 51);">苹果公司在 2007 年率先推出了触摸屏键盘，但一直没多大改进。在这一方面， Android 则将键盘权限开放给了第三方开发者，所以出现了许多像 Swype ， SwiftKey 等优秀的键盘输入法。在 iOS 8 中，苹果终于将键盘权限开发给了第三方开发者，自定义键盘输入法可以让用户在整个系统范围内使用。</span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/02738AE2-4E63-40F2-980A-B9D63FA0991A.png" height="449" width="241"/></div>
<div><br/></div>
<div><span style="font-size: 18px;"><b>以下是iOS 9中新增扩展</b></span></div>
<div><b><span style="font-size: 18px;"><br/></span></b></div>
<div><span style="font-size: 18px;"><b>网络扩展</b></span></div>
<div><b><span style="font-size: 18px;"><br/></span></b></div>
<div><font color="#333333">开发者可以通过改扩展来实现自定义的VPN客户端、透明的网络代理客户端以及实现动态的设备端网络内容过滤。</font></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><b><span style="font-size: 18px;"><font color="#333333">Safari扩展</font></span></b></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><span style="color: rgb(51, 51, 51);">该扩展可以让用户通过Safari的分享链接看到你的内容。又或者提供一个屏蔽列表，让你的用户使用你的App浏览Web内容时屏蔽指定的内容。</span></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><b><span style="font-size: 18px;"><span style="color: rgb(51, 51, 51);">Spotlight扩展</span></span></b></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><span style="color: rgb(51, 51, 51);">该扩展可以</span><span style="color: rgb(51, 51, 51);">对App内的数据进行索引，并且可以在不重启App的情况下重建数据索引。</span></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><b><span style="font-size: 18px;"><span style="color: rgb(51, 51, 51);">Audio Unit扩展</span></span></b></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><span style="color: rgb(51, 51, 51);">该扩展允许App提供类似于GarageBand，Logic等App提供的乐器演奏，音频特效，声音合成功能。</span></div>
<div><span style="font-size: 16px;"><span style="color: rgb(51, 51, 51);"><br/></span></span></div>
<div><b><span style="font-size: 24px;"><font color="#333333">2. 转入正题 － Share Extension</font></span></b></div>
<div><br/></div>
<div>本篇文章主要是探讨Share Extension的开发与使用。下面会结合一个例子对其做一个全面的探讨和深入的了解。</div>
<div><span style="font-family: Helvetica;"><br/></span></div>
<div><span style="font-size: 18px;"><span style="font-family: Helvetica;"><b>2.1.  创建Share Extension扩展Target</b></span></span></div>
<div><b><span style="font-family: Helvetica;"><br/></span></b></div>
<div><span style="color: rgb(255, 38, 0);"><span style="font-family: Helvetica;">注：扩展不能单独创建，必须依赖于应用工程项目，因此如果你还没有创建一个应用工程，先去创建一个。</span></span></div>
<div><span style="font-size: 11px;"><span style="font-family: Helvetica;"><br/></span></span></div>
<div><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);">1、打开项目设置，在TARGETS侧栏地下点击“＋”号来创建一个新的Target，如图：</span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/83A186AF-B177-4593-BB9E-7435E8EE7758.png" height="599" width="360"/></div>
<div><br/></div>
<div><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);">2、然后选择”iOS” -&gt; “Application Extension” -&gt; “Share Extension”，点击“Next”。如图：</span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/E9C784D1-6614-4D17-ADEB-130A966781E3.png" height="342" width="482"/></div>
<div><br/></div>
<div><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);">3、给扩展起个名字，这里填写了“Share”，点击“Finish”。如图：</span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/39D204D5-ACD8-4506-A164-9FFB951D47F6.png" height="342" width="482"/></div>
<div><br/></div>
<div><span style="font-family: Helvetica;">4、这时候会提示创建一个Scheme，点击“Activate”。如图：</span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/2A157585-E20E-47EA-8C78-5C52C6BED9B2.png" height="185" width="420"/></div>
<div><br/></div>
<div><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);">那么，直到这里创建Share Extension的工作就算是完成了。接下来可以先进行一下编译运行。这里跟做App开发的时候会稍微有点不一样。因为Extension是需要Host App（宿主应用）来运行的。所以，XCode中会弹出界面让我们选择一个iOS的App来运行Extension。如图：</span></div>
<div><span style="font-family: Helvetica;"><br/></span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/F9947728-6B8F-48D5-B19A-16393648573C.png" height="409" width="442"/></div>
<div><br/></div>
<div><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);">这里我选择了XCode建议的应用Safari，然后点击“Run”来进行调试运行。XCode会启动Safari，如图：</span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/4700AB4F-D683-40A9-B39C-14C63AB7EB01.png" height="482" width="264"/></div>
<div><br/></div>
<div><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);">能看到Safari中间的分享按钮是灰色不可用的。别急，你还没打开一个网页呢^_^。我们随便点开一个网页，可以看到分享按钮变为激活状态。点击分享按钮就会弹出分享菜单，如图：</span></div>
<div><span style="font-family: Helvetica;"><br/></span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/5C7B3F5E-A029-42FF-B677-FC39E210794F.png" height="417" width="227"/></div>
<div><br/></div>
<div><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);">可以看到刚才建立的Share扩展已经显示在面板上了，如果你没有发现自己的扩展，那么你可以将菜单滑动到最右边，在“更多”选项中激活自己的扩展。如图：</span></div>
<div><span style="font-family: Helvetica;"><br/></span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/284F61FC-0584-4227-9A5F-8C4AFA434649.png" height="493" width="269"/></div>
<div><span style="font-family: Helvetica;">我们点击自己创建的分享项，其弹出一个分享窗口。如图：</span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/BC3F0D13-5615-4810-A433-BE67F5A89414.png" height="758" width="414"/></div>
<div><span style="font-family: Helvetica;"><br/></span></div>
<div><span style="font-size: 18px;"><b><span style="font-family: Helvetica;">2.2. 配置Share Extension</span></b></span></div>
<div><span style="font-family: Helvetica;"><br/></span></div>
<div><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);">接下来我们需要给他一些设置。我们展开XCode左侧栏的Share目录，找到Info.plist文件。如：</span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/CE456EDF-B8C8-42B3-B795-4B5BBFBBE7C2.png" height="426" width="1039"/></div>
<div><br/></div>
<div><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);">我们只需要关注以下几个字段的设置：</span></div>
<table style="border-collapse: collapse;width:858px;" cellspacing="0" cellpadding="0">
<tr>
<td style="border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;width:41.02564102564102%;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">Bundle display name</font></span></p>
</td>
<td style="border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;width:58.857808857808855%;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">扩展的显示名称，默认跟你的项目名称相同，可以通过修改此字段来控制扩展的显示名称。</font></span></p>
</td>
</tr>
<tr>
<td style=" background-color: #efefef; border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtension</font></span></p>
</td>
<td style=" background-color: #efefef; border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">扩展描述字段，用于描述扩展的属性、设置等。作为一个扩展项目必须要包含此字段。</font></span></p>
</td>
</tr>
<tr>
<td style=" border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionAttributes</font></span></p>
</td>
<td style=" border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">扩展属性集合字段。用于描述扩展的属性。</font></span></p>
</td>
</tr>
<tr>
<td style=" background-color: #efefef; border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationRule</font></span></p>
</td>
<td style=" background-color: #efefef; border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">激活扩展的规则。默认为字符串</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">“TRUEPREDICATE”</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">，表示在分享菜单中一直显示该扩展。可以将类型改为</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">Dictionary</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">类型，然后添加以下字段：</font></span></p>
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationSupportsAttachmentsWithMaxCount</font></span></p>
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationSupportsAttachmentsWithMinCount</font></span></p>
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationSupportsImageWithMaxCount</font></span></p>
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationSupportsMovieWithMaxCount</font></span></p>
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationSupportsWebPageWithMaxCount</font></span></p>
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationSupportsWebURLWithMaxCount</font></span></p>
</td>
</tr>
<tr>
<td style=" border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionMainStoryboard</font></span></p>
</td>
<td style=" border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">设置主界面的</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">Storyboard</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">，如果不想使用</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">storyboard</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">，也可以使用</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionPrincipalClass</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">指定自定义</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">UIViewController</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">子类名</font></span></p>
</td>
</tr>
<tr>
<td style=" background-color: #efefef; border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionPointIdentifier</font></span></p>
</td>
<td style=" background-color: #efefef; border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">扩展标识，在分享扩展中为：</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">com.apple.share-services</font></span></p>
</td>
</tr>
<tr>
<td style=" border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionPrincipalClass</font></span></p>
</td>
<td style=" border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">自定义</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">UI</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">的类名</font></span></p>
</td>
</tr>
<tr>
<td style=" background-color: #efefef; border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationSupportsAttachmentsWithMaxCount</font></span></p>
</td>
<td style=" background-color: #efefef; border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">附件最多限制，为数值类型。附件包括</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">File</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">、</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">Image</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">和</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">Movie</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">三大类，单一、混选总量不超过指定数量</font></span></p>
</td>
</tr>
<tr>
<td style=" border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationSupportsAttachmentsWithMinCount</font></span></p>
</td>
<td style=" border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">附件最少限制，为数值类型。当设置</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationSupportsAttachmentsWithMaxCount</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">时生效，默认至少选择</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">1</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">个附件，分享菜单中才显示扩展插件图标。</font></span></p>
</td>
</tr>
<tr>
<td style=" background-color: #efefef; border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationSupportsFileWithMaxCount</font></span></p>
</td>
<td style=" background-color: #efefef; border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">文件最多限制，为数值类型。文件泛指除</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">Image/Movie</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">之外的附件，例如【邮件】附件、【语音备忘录】等。</font></span></p>
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">单一、混选均不超过指定数量。</font></span></p>
</td>
</tr>
<tr>
<td style=" border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000"> NSExtensionActivationSupportsImageWithMaxCount</font></span></p>
</td>
<td style=" border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">图片最多限制，为数值类型。单一、混选均不超过指定数量。</font></span></p>
</td>
</tr>
<tr>
<td style=" background-color: #efefef; border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationSupportsMovieWithMaxCount</font></span></p>
</td>
<td style=" background-color: #efefef; border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">视频最多限制，为数值类型。单一、混选均不超过指定数量。</font></span></p>
</td>
</tr>
<tr>
<td style=" border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationSupportsText</font></span></p>
</td>
<td style=" border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">是否支持文本类型，布尔类型，默认不支持。如【备忘录】的分享</font></span></p>
</td>
</tr>
<tr>
<td style=" background-color: #efefef; border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationSupportsWebURLWithMaxCount</font></span></p>
</td>
<td style=" background-color: #efefef; border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">Web</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">链接最多限制，为数值类型。默认不支持分享超链接，需要自己设置一个数值。</font></span></p>
</td>
</tr>
<tr>
<td style=" border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationSupportsWebPageWithMaxCount</font></span></p>
</td>
<td style=" border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #000000 #000000 #000000 #000000; padding: 4.0px 4.0px 4.0px 4.0px;" valign="top">
<p style=""><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">Web</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">页面最多限制，为数值类型。默认不支持</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">Web</font><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: 'PingFang SC'; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="PingFang SC" color="#000000">页面分享，需要自己设置一个数值。</font></span></p>
</td>
</tr>
</table>
<div><br/></div>
<div>对于不同的应用里面有可能出现只允许接受某种类型的内容，那么Share Extension就不能一直出现在分享菜单中，因为不同的应用提供的分享内容不一样，这就需要通过设置<font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationRule字段来决定Share Extension是否显示。例如，只想接受其他应用分享链接到自己的应用，那么可以通过下面的步骤来设置：</font></div>
<div><span style="font-family: Helvetica;"><br/></span></div>
<ol>
<li><span style="font-family: Helvetica;">将</span><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationRule字段类型由String改为Dictionary。</font></span></li>
<li><span style="font-size: 13px;"><span style="font-family: Helvetica;">展开</span></span><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationRule字段，创建其子项</font></span><span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionActivationSupportsWebURLWithMaxCount，并设置一个限制数量。</font></span></li>
</ol>
<div><br/></div>
<div><span style="font-size: 13px;"><span style="font-family: Helvetica;">调整后如下图所示：</span></span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/93A142FA-FC72-4446-B13F-4BCD5CC3E10A.png" height="354" width="755"/></div>
<div><b><span style="font-size: 18px;">2.3. 处理Share Extension中的数据</span></b></div>
<div><b><span style="font-size: 18px;"><br/></span></b></div>
<div>其实在Share Extension中默认都会有一个数据展现的UI界面。该界面继承<span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">SLComposeServiceViewController这个类型，如：</span></div>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@interface</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">ShareViewController :</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">SLComposeServiceViewController</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
<br/></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@end</span></div>
</td>
</tr>
</table>
<div><br/></div>
<div>其展现效果，如图：</div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/0A4BF95E-CFB3-4E77-A5B1-783DF4910C16.png" height="211" width="400"/></div>
<div>顶部包括了标题、取消（Cancel）按钮和提交（Post）按钮。然后下面跟着左边就是一个文本编辑框，右边就是一个图片显示控件。那么，每当用户点击取消按钮或者提交按钮时，都会分别触发下面的方法：</div>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">/**<br/>
 * </span> <span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">点击取消按钮</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400"><br/>
 */</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)didSelectCancel<br/>
{<br/>
    [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">super</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">didSelectCancel</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;"><span style="font-size: 11px;"><span style="font-family: Menlo;">];</span></span></span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">}</span></span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;"><br/></span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">/**<br/>
 * </span> <span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">点击提交按钮</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400"><br/>
 */</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)didSelectPost<br/>
{<br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
    [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">extensionContext</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">completeRequestReturningItems</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">@[]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">completionHandler</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nil</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;"><span style="font-size: 11px;"><span style="font-family: Menlo;">];</span></span></span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">}</span></span></div>
</td>
</tr>
</table>
<div><br/></div>
<div>在这两个方法里面可以进行一些自定义的操作。一般情况下，当用户点击提交按钮的时候，扩展要做的事情就是要把数据取出来，并且放入一个与<span style="color: rgb(51, 51, 51);">C</span><span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, STheiti, 微软雅黑, 黑体, Arial, Tahoma, sans-serif, serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; background-color: rgb(255, 255, 255);">ontaining App（容器程序，</span><span style="color: rgb(255, 38, 0);">尽管苹果开放了Extension，但是在iOS中extension并不能单独存在，要想提交到AppStore，必须将Extension包含在一个App中提交，并且App的实现部分不能为空,这个包含Extension的App就叫Containing app。Extension会随着Containing App的安装而安装，同时随着ContainingApp的卸载而卸载。</span><span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, STheiti, 微软雅黑, 黑体, Arial, Tahoma, sans-serif, serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; background-color: rgb(255, 255, 255);">）</span>共享的数据介质中（包括NSUserDefault、Sqlite、CoreData），要跟容器程序进行数据交互需要借助AppGroups服务，下面的章节会对这块进行详细说明。下面先来看看怎么获取扩展中的数据。</div>
<div><br/></div>
<div>在ShareExtension中，UIViewController包含一个extensionContext这样的上下文对象：</div>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@interface</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">UIViewController(NSExtensionAdditions) &lt;</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSExtensionRequestHandling</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&gt;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Returns the extension context. Also acts as a convenience method for a view controller to check if it participating in an extension request.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@property</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nullable</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nonatomic</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">readonly</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">strong</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSExtensionContext</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*extensionContext</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_AVAILABLE_IOS</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_0);<br/>
<br/></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@end</span></div>
</td>
</tr>
</table>
<div><br/></div>
<div>通过操作它就可以获取到分享的数据，返回宿主应用的界面等操作。我们可以先看一下extensionContext的定义。</div>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_CLASS_AVAILABLE</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">10</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_10,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_0)<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@interface</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionContext :</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSObject</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// The list of input NSExtensionItems associated with the context. If the context has no input items, this array will be empty.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@property</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">readonly</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">copy</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_NONATOMIC_IOSONLY</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSArray</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*inputItems;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Signals the host to complete the app extension request with the supplied result items. The completion handler optionally contains any work which the extension may need to perform after the request has been completed, as a background-priority task. The `expired` parameter will be YES if the system decides to prematurely terminate a previous non-expiration invocation of the completionHandler. Note: calling this method will eventually dismiss the associated view controller.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)completeRequestReturningItems:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nullable</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSArray</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)items completionHandler:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(^</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__nullable</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">expired))completionHandler;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Signals the host to cancel the app extension request, with the supplied error, which should be non-nil. The userInfo of the NSError will contain a key NSExtensionItemsAndErrorsKey which will have as its value a dictionary of NSExtensionItems and associated NSError instances.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)cancelRequestWithError:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSError</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)error;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Asks the host to open an URL on the extension's behalf</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)openURL:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)URL completionHandler:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(^</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__nullable</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">success))completionHandler;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@end</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Key in userInfo. Value is a dictionary of NSExtensionItems and associated NSError instances.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">FOUNDATION_EXTERN</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">const</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionItemsAndErrorsKey</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_AVAILABLE</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">10</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_10,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_0);<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// The host process will enter the foreground</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">FOUNDATION_EXTERN</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">const</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionHostWillEnterForegroundNotification</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_AVAILABLE_IOS</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_2);<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// The host process did enter the background</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">FOUNDATION_EXTERN</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">const</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionHostDidEnterBackgroundNotification</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_AVAILABLE_IOS</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_2);<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// The host process will resign active status (stop receiving events), the extension may be suspended</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">FOUNDATION_EXTERN</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">const</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionHostWillResignActiveNotification</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_AVAILABLE_IOS</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_2);<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// The host process did become active (begin receiving events)</span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">FOUNDATION_EXTERN</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">const</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionHostDidBecomeActiveNotification</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_AVAILABLE_IOS</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_2);</span></div>
</td>
</tr>
</table>
<div><br/></div>
<div>NSExtensionContext的结构比较简单，包含一个属性和三个方法。其说明如下：</div>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;margin-left:0px;table-layout:fixed;width:100%;">
<tr>
<td style="border: 1px solid rgb(219, 219, 219); padding: 10px; margin: 0px;width:33.7995337995338%;">
<div><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">inputItems</span></div>
</td>
<td style="border: 1px solid rgb(219, 219, 219); padding: 10px; margin: 0px;width:66.08391608391608%;">
<div>该数组存储着容器应用传入给NSExtensionContext的<span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">NSExtensionItem数组。其中每个NSExtensionItem标识了一种类型的数据。要获取数据就要从这个属性入手。</span></div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">completeRequestReturningItems:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">completionHandler:</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>通知宿主程序的扩展已完成请求。调用此方法后，扩展UI会关闭并返回容器程序中。其中的items就是返回宿主程序的数据项。</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">cancelRequestWithError:</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>通知宿主程序的扩展已取消请求。调用此方法后，扩展UI会关闭并返回容器程序中。其中error为错误的描述信息。</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionItemsAndErrorsKey</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">NSExtensionItem的userInfo属性中对应的错误信息键名。</span></div>
</td>
</tr>
</table>
<div><br/></div>
<div>类的下面还定义了一些通知，这些通知都是跟宿主程序的行为相关，在设计扩展的时候可以根据这些通知来进行对应的操作。其说明如下：</div>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50.23310023310024%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionHostWillEnterForegroundNotification</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:49.65034965034965%;">
<div>宿主程序将要返回前台通知</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionHostDidEnterBackgroundNotification</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>宿主程序进入后台通知</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionHostWillResignActiveNotification</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>宿主程序将要被挂起通知</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionHostDidBecomeActiveNotification</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>宿主程序被激活通知</div>
</td>
</tr>
</table>
<div><br/></div>
<div><b>2.3.1 从inputItems中获取数据</b></div>
<div><b><span style="font-size: 18px;"><br/></span></b></div>
<div>inputItems是包含NSExtensionItem类型对象的数组。那么，要处理里面的数据还得先来了解一下NSExtensionItem的结构：</div>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@interface</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionItem :</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSObject</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&lt;</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSCopying</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSSecureCoding</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&gt;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// (optional) title for the item</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@property</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nullable</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">copy</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_NONATOMIC_IOSONLY</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSAttributedString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*attributedTitle;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// (optional) content text</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@property</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nullable</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">copy</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_NONATOMIC_IOSONLY</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSAttributedString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*attributedContentText;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// (optional) Contains images, videos, URLs, etc. This is not meant to be an array of alternate data formats/types, but instead a collection to include in a social media post for example. These items are always typed NSItemProvider.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@property</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nullable</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">copy</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_NONATOMIC_IOSONLY</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSArray</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*attachments;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// (optional) dictionary of key-value data. The key/value pairs accepted by the service are expected to be specified in the extension's Info.plist. The values of NSExtensionItem's properties will be reflected into the dictionary.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@property</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nullable</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">copy</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_NONATOMIC_IOSONLY</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSDictionary</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*userInfo;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@end</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Keys corresponding to properties exposed on the NSExtensionItem interface</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">FOUNDATION_EXTERN</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">const</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionItemAttributedTitleKey</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_AVAILABLE</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">10</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_10,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_0);<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">FOUNDATION_EXTERN</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">const</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionItemAttributedContentTextKey</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_AVAILABLE</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">10</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_10,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_0);</span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">FOUNDATION_EXTERN</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">const</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionItemAttachmentsKey</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_AVAILABLE</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">10</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_10,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_0);</span></div>
</td>
</tr>
</table>
<div><br/></div>
<div>NSExtensionItem包含四个属性</div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50.23310023310024%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">attributedTitle</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:49.65034965034965%;">
<div>标题。</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">attributedContentText</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>内容。</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">attachments</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>附件数组，包含图片、视频、链接等资源，封装在NSItemProvider类型中。</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">userInfo</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>一个key－value结构的数据。NSExtensionItem中的属性都会在这个属性中一一映射。</div>
</td>
</tr>
</table>
<div><br/></div>
<div><span style="font-size: 13px;"><span style="font-family: Helvetica;">对应userInfo结构中的NSExtensionItem属性的键名如下：</span></span></div>
<div><span style="font-size: 13px;"><span style="font-family: Helvetica;"><br/></span></span></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50.23310023310024%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionItemAttributedTitleKey</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:49.65034965034965%;">
<div>标题的键名</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionItemAttributedContentTextKey</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>内容的键名</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionItemAttachmentsKey</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>附件的键名</div>
</td>
</tr>
</table>
<div><span style="font-size: 13px;"><span style="font-family: Helvetica;"><br/></span></span></div>
<div><span style="font-size: 13px;"><span style="font-family: Helvetica;">从上面的定义可以看出除了文本内容，其他类型的内容都是作为附件存储的，而附件又是封装在一个叫NSItemProvider的类型中，其定义如下：</span></span></div>
<div><span style="font-size: 13px;"><span style="font-family: Helvetica;"><br/></span></span></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">typedef</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(^NSItemProviderCompletionHandler)(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__nullable</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">id</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&lt;</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSSecureCoding</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&gt; item,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSError</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">error);<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">typedef</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(^NSItemProviderLoadHandler)(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSItemProviderCompletionHandler</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">completionHandler,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">Class expectedValueClass,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSDictionary</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">options);<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// An NSItemProvider is a high level abstraction for file-like data objects supporting multiple representations and preview images.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_CLASS_AVAILABLE</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">10</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_10,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_0)<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@interface</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSItemProvider :</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSObject</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&lt;</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSCopying</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&gt;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Initialize an NSItemProvider with a single handler for the given item.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">instancetype</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)initWithItem:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nullable</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">id</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&lt;</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSSecureCoding</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&gt;)item typeIdentifier:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nullable</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)typeIdentifier</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_DESIGNATED_INITIALIZER</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Initialize an NSItemProvider with load handlers for the given file URL, and the file content.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nullable</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">instancetype</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)initWithContentsOfURL:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)fileURL;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Sets a load handler block for a specific type identifier. Handlers are invoked on demand through loadItemForTypeIdentifier:options:completionHandler:. To complete loading, the implementation has to call the given completionHandler. Both expectedValueClass and options parameters are derived from the completionHandler block.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)registerItemForTypeIdentifier:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)typeIdentifier loadHandler:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSItemProviderLoadHandler</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)loadHandler;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Returns the list of registered type identifiers</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@property</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">copy</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">readonly</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_NONATOMIC_IOSONLY</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSArray</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*registeredTypeIdentifiers;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Returns YES if the item provider has at least one item that conforms to the supplied type identifier.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)hasItemConformingToTypeIdentifier:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)typeIdentifier;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Loads the best matching item for a type identifier. The client's expected value class is automatically derived from the blocks item parameter. Returns an error if the returned item class does not match the expected value class. Item providers will perform simple type coercions (eg. NSURL to NSData, NSURL to NSFileWrapper, NSData to UIImage).</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)loadItemForTypeIdentifier:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)typeIdentifier options:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nullable</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSDictionary</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)options completionHandler:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nullable</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSItemProviderCompletionHandler</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)completionHandler;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@end</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Common keys for the item provider options dictionary.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">FOUNDATION_EXTERN</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">const</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSItemProviderPreferredImageSizeKey</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_AVAILABLE</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">10</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_10,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_0);</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// NSValue of CGSize or NSSize, specifies image size in pixels.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@interface</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSItemProvider(NSPreviewSupport)<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Sets a custom preview image handler block for this item provider. The returned item should preferably be NSData or a file NSURL.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@property</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nullable</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">copy</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_NONATOMIC_IOSONLY</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSItemProviderLoadHandler</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">previewImageHandler</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_AVAILABLE</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">10</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_10,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_0);<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Loads the preview image for this item by either calling the supplied preview block or falling back to a QuickLook-based handler. This method, like loadItemForTypeIdentifier:options:completionHandler:, supports implicit type coercion for the item parameter of the completion block. Allowed value classes are: NSData, NSURL, UIImage/NSImage.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)loadPreviewImageWithOptions:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSDictionary</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)options completionHandler:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSItemProviderCompletionHandler</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)completionHandler</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_AVAILABLE</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">10</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_10,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_0);<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@end</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Keys used in property list items received from or sent to JavaScript code</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// If JavaScript code passes an object to its completionFunction, it will be placed into an item of type kUTTypePropertyList, containing an NSDictionary, under this key.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">FOUNDATION_EXTERN</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">const</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionJavaScriptPreprocessingResultsKey</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_AVAILABLE</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">10</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_10,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_0);<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Arguments to be passed to a JavaScript finalize method should be placed in an item of type kUTTypePropertyList, containing an NSDictionary, under this key.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">FOUNDATION_EXTERN</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">const</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSExtensionJavaScriptFinalizeArgumentKey</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_AVAILABLE_IOS</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_0);<br/>
<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Errors</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Constant used by NSError to distinguish errors belonging to the NSItemProvider domain</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">FOUNDATION_EXTERN</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">const</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">NSItemProviderErrorDomain</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_AVAILABLE</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">10</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_10,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_0);<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// NSItemProvider-related error codes</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">typedef</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">NS_ENUM</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(NSInteger, NSItemProviderErrorCode) {<br/>
    NSItemProviderUnknownError                                      = -</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">1</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,<br/>
    NSItemProviderItemUnavailableError                              = -</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">1000</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,<br/>
    NSItemProviderUnexpectedValueClassError                         = -</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">1100</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,<br/>
    NSItemProviderUnavailableCoercionError</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_AVAILABLE</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">10</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_11,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">9</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_0) = -</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">1200</span></div>
<div><span style="font-family: Menlo;"><span style="font-size: 11px;">} <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_ENUM_AVAILABLE</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">10</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_10,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_0);</span></span></span></div>
</td>
</tr>
</table>
<div><span style="font-size: 13px;"><span style="font-family: Helvetica;"><br/></span></span></div>
<div>NSItemProvider结构说明</div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50.23310023310024%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">initWithItem:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">typeIdentifier:</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:49.65034965034965%;">
<div>初始化方法，item为附件的数据，typeIdentifier是附件对应的类型标识,对应UTI的描述。</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">initWithContentsOfURL:</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>根据制定的文件路径来初始化。</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">registerItemForTypeIdentifier:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">loadHandler:</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>为一种资源类型自定义加载过程。这个方法主要针对自定义资源使用，例如自己定义的类或者文件格式等。当调用<span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;"><span style="font-family: Menlo;"><span style="font-size: 11px;">loadItemForTypeIdentifier:</span></span></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">options:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">completionHandler:</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">方法时就会触发定义的加载过程。</span></div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">hasItemConformingToTypeIdentifier:</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>用于判断是否有typeIdentifier(UTI)所指定的资源存在。存在则返回YES，否则返回NO。该方法结合<span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;"><span style="font-family: Menlo;"><span style="font-size: 11px;">loadItemForTypeIdentifier:</span></span></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">options:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">completionHandler:</span>使用。</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;"><span style="font-family: Menlo;"><span style="font-size: 11px;">loadItemForTypeIdentifier:</span></span></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">options:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">completionHandler:</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>加载typeIdentifier指定的资源。加载是一个异步过程，加载完成后会触发completionHandler。</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">loadPreviewImageWithOptions:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">completionHandler:</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>加载资源的预览图片。</div>
</td>
</tr>
</table>
<div><br/></div>
<div><span style="font-size: 13px;"><span style="font-family: Helvetica;">由此可见，其结构如下图所示：</span></span></div>
<div><span style="font-size: 13px;"><span style="font-family: Helvetica;"><br/></span></span></div>
<div style="text-align: center"><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/ShareExtension%E5%B1%82%E6%AC%A1%E7%BB%93%E6%9E%84.png" height="732" width="869"/></div>
<div><span style="font-size: 13px;"><span style="font-family: Helvetica;"><br/></span></span></div>
<div><span style="font-size: 13px;"><span style="font-family: Helvetica;">为了要取到宿主程序提供的数组，那么只要关注loadItemTypeIdentifier:options:completionHandler方法的使用即可。有了上面的了解，那么接下来就是对inputItems进行数据分析并提取了，这里以一个链接的分享为例，改写视图控制器中的</span></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">didSelectPost</span><span style="font-size: 13px;"><span style="font-family: Helvetica;">方法。看下面的代码：</span></span></div>
<div><span style="font-size: 13px;"><span style="font-family: Helvetica;"><br/></span></span></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)didSelectPost<br/>
{<br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__block</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">hasExistsUrl =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">NO</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;"><span style="font-size: 11px;"><span style="font-family: Menlo;">;</span></span></span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">    [<span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">extensionContext</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">inputItems</span></span></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">enumerateObjectsUsingBlock</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:^(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSExtensionItem</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nonnull</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">extItem</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSUInteger</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">idx,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nonnull</span> <span style="font-size: 11px;"><span style="font-family: Menlo;">stop) {</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">       <br/>
        [item.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">attachments</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">enumerateObjectsUsingBlock</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:^(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSItemProvider</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nonnull</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">itemProvider,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSUInteger</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">idx,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nonnull</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">stop) {<br/>
           <br/>
           </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">if</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">([itemProvider</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">hasItemConformingToTypeIdentifier</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"public.url"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">])<br/>
            {<br/>
                [itemProvider</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">loadItemForTypeIdentifier</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"public.url"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
                                               </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">options</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nil</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
                                     </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">completionHandler</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:^(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">id</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&lt;</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSSecureCoding</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&gt; </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nullable</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">item,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSError</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">error) {<br/>
                                         <br/>
                                         </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">if</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">([(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSObject</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)item</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">isKindOfClass</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">class</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]])<br/>
                                          {<br/>
                                             </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">NSLog</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b">分享的</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">URL = %@"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">, item);<br/>
                                          }<br/>
                                         <br/>
                                      }];<br/>
               <br/>
                hasExistsUrl =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">YES</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
                *stop =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">YES</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
            }<br/>
           <br/>
        }];<br/>
       <br/>
       </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">if</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(hasExistsUrl)<br/>
        {<br/>
            *stop =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">YES</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
        }<br/>
       <br/>
    }];<br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//    [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];</span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">}</span></span></div>
</td>
</tr>
</table>
<div><span style="font-size: 13px;"><span style="font-family: Helvetica;"><br/></span></span></div>
<div>上面的例子中遍历了extensionContext的inputItems数组中所有NSExtensionItem对象，然后从这些对象中遍历attachments数组中的所有NSItemProvider对象。匹配第一个包含public.url标识的附件（具体要匹配什么资源，数量是多少皆有自己的业务所决定）。<span style="color: rgb(255, 38, 0);"><b>注意：在上面代码中注释了</b></span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;"><span style="color: rgb(255, 38, 0);"><b><span style="font-family: Menlo;"><span style="font-size: 11px;">[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];</span></span>这行代码，主要是使到视图控制器不被关闭，等到实现相应的处理后再进行调用该方法，对分享视图进行关闭。</b></span>在下面的章节会说明这一点。</span></div>
<div><br/></div>
<div><b>2.3.2 将分享数据传递给容器程序</b></div>
<div><br/></div>
<div>上面章节已经讲述了如何取得宿主应用所分享的内容。那么，接下来就是将这些内容传递给容器程序进行相应的操作（如：在一款社交应用中，可能会为取得的分享内容发布一条用户动态）。在默认情况下，iOS的应用是存在一个沙盒里面的，不允许应用与应用直接进行数据的交互。为此，苹果提供了一项叫App Groups的服务，该服务允许开发者可以在自己的应用之间通过NSUserDefaults、NSFileManager或者CoreData来进行相互的数据传输。下面介绍如何激活App Groups服务：</div>
<div><br/></div>
<ul>
<li>首先要有一个独立的AppID（带通配符＊号的AppID是不允许激活App Groups的）</li>
</ul>
<div style="text-align: center"><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/2EB839B9-44EF-416E-AB6F-FA1E33291EA9.png" height="935" width="689"/></div>
<ul>
<li>然后打开容器应用的项目配置的Capabilities页签，激活App Groups特性，如图：</li>
</ul>
<div style="text-align: center"><br/></div>
<div style="text-align: center"><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/9137480F-2EBC-48CF-BB0B-3F368A5312E8.png" height="573" width="901"/></div>
<div style="text-align: center"><br/></div>
<ul>
<li>点击＋号添加一个App Groups，点击OK按钮</li>
</ul>
<div><br/></div>
<div style="text-align: center"><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/26116A6E-F8CB-4ED3-B421-7F633DE6D29D.png" height="250" width="703"/></div>
<div style="text-align: center"><br/></div>
<ul>
<li>创建完成后，XCode会自动把应用添加到新建的分组中。如图：</li>
</ul>
<div><br/></div>
<div style="text-align: center"><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/B9B4E90F-B036-408E-859D-97A9A54C631F.png" height="580" width="908"/></div>
<div style="text-align: center"><br/></div>
<ul>
<li>上述步骤完成后，容器程序的App Groups已经算是设置完成。然后轮到Share Extension插件需要激活App Groups服务，设置步骤跟容器程序相同，唯一不同的是，插件不需要创建新的App Group，只要加入到容器程序刚才创建的Group即可（这里可以理解为，哪些应用要实现共享数据，那么他们必须在同一个Group里面）。如图：</li>
</ul>
<div><br/></div>
<div style="text-align: center"><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/A9B8A061-7667-4A84-81E7-90B89DBF0A62.png" height="578" width="915"/></div>
<div><br/></div>
<div>至此，应用和扩展的App Groups服务都已经启动，现在就要进行分享内容的传输操作。下面分别介绍一下NSUserDefaults、NSFileManager以及CoreData三种方式是如何实现App Groups下的数据操作：</div>
<div><br/></div>
<ul>
<li>NSUserDefaults：要想设置或访问Group的数据，不能在使用<span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">standardUserDefaults方法来获取一个NSUserDefaults对象了。应该使用</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">initWithSuiteName:方法来初始化一个NSUserDefaults对象，其中的SuiteName就是创建的Group的名字，然后利用这个对象来实现，跨应用的数据读写，代码如下：</span></li>
</ul>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">初始化一个供</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">App Groups</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">使用的</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">NSUserDefaults</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">对象</span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;"><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSUserDefaults</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*userDefaults = [[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSUserDefaults</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">alloc</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>initWithSuiteName</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"group.cn.vimfung.ShareExtensionDemo"</span>];</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">   </span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;"><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span></span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">写入数据</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">[userDefaults</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">setValue</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"value"</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">forKey</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"key"</span><span style="font-family: Menlo;"><span style="font-size: 11px;">];</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">   </span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;"><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span></span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">读取数据</span></span></div>
<div><span style="font-family: Menlo;"><span style="font-size: 11px;"><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">NSLog</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"%@"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">, [userDefaults</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">valueForKey</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"key"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]);</span></span></span></div>
</td>
</tr>
</table>
<div><br/></div>
<div><br/></div>
<ul>
<li>NSFileManager：通过调用 <span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">containerURLForSecurityApplicationGroupIdentifier:方法可以获得AppGroup的共享目录，然后在此目录的基础上实现任意的文件操作。代码如下：</span></li>
</ul>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">获取分组的共享目录</span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;"><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*groupURL = [[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSFileManager</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">defaultManager</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>containerURLForSecurityApplicationGroupIdentifier</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"group.cn.vimfung.ShareExtensionDemo"</span>];</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*fileURL = [groupURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">URLByAppendingPathComponent</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"demo.txt"</span><span style="font-family: Menlo;"><span style="font-size: 11px;">];</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">   </span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;"><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span></span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">写入文件</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"abc"</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">writeToURL</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:fileURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">atomically</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">YES</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">encoding</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">NSUTF8StringEncoding</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">error</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nil</span><span style="font-family: Menlo;"><span style="font-size: 11px;">];</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">   </span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;"><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span></span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">读取文件</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*str = [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">stringWithContentsOfURL</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:fileURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">encoding</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">NSUTF8StringEncoding</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">error</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nil</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;"><span style="font-size: 11px;"><span style="font-family: Menlo;">];</span></span></span></div>
<div><span style="font-family: Menlo;"><span style="font-size: 11px;"><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">NSLog</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"str = %@"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">, str);</span></span></span></div>
</td>
</tr>
</table>
<div><br/></div>
<ul>
<li>CoreData：其实CoreData是基于NSFileManager取得共享目录后来实现数据共享的。即在初始化CoreData时，先使用NSFileManager取得共享目录，然后再指定共享目录为存储数据文件的目录（如存储的sqlite文件）。代码如下：</li>
</ul>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;background-color:rgb(255,255,255);width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">获取分组的共享项目</span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;"><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*containerURL = [[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSFileManager</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">defaultManager</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">containerURLForSecurityApplicationGroupIdentifier</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"group.cn.vimfung.ShareExtensionDemo"</span>];</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*<b>storeURL</b> = [containerURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">URLByAppendingPathComponent</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"DataModel.sqlite"</span><span style="font-family: Menlo;"><span style="font-size: 11px;">];</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">   </span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;"><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span></span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">初始化持久化存储调度器</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*modelURL = [[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSBundle</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">mainBundle</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">URLForResource</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"DataModel"</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">withExtension</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"momd"</span><span style="font-family: Menlo;"><span style="font-size: 11px;">];</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">   </span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;"><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSManagedObjectModel</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*model = [[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSManagedObjectModel</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">alloc</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">initWithContentsOfURL</span>:modelURL];</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSPersistentStoreCoordinator</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*coordinator = [[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSPersistentStoreCoordinator</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">alloc</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">initWithManagedObjectModel</span><span style="font-family: Menlo;"><span style="font-size: 11px;">:model];</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">   </span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">[coordinator <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">addPersistentStoreWithType</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSSQLiteStoreType</span></span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">                         </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">configuration</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nil</span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">                                    </span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">URL</span><span style="font-family: Menlo;"><span style="font-size: 11px;">:<b>storeURL</b></span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">                               </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">options</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nil</span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">                                 </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">error</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nil</span><span style="font-family: Menlo;"><span style="font-size: 11px;">];</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">   </span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;"><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span></span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">创建受控对象上下文</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSManagedObjectContext</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*context = [[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSManagedObjectContext</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">alloc</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">initWithConcurrencyType</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">NSMainQueueConcurrencyType</span><span style="font-family: Menlo;"><span style="font-size: 11px;">];</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">   </span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">[context <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">performBlockAndWait</span>:^{</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">    [context</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">setPersistentStoreCoordinator</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;"><span style="font-size: 11px;"><span style="font-family: Menlo;">:coordinator];</span></span></span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">}];</span></span></div>
</td>
</tr>
</table>
<div><br/></div>
<div>为了方便演示，这里会使用NSUserDefault来直接把取到的url地址保存起来。代码如下所示：</div>
<div><br/></div>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">/**<br/>
 * </span> <span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">点击提交按钮</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400"><br/>
 */</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)didSelectPost<br/>
{<br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__block</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">hasExistsUrl =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">NO</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;"><span style="font-size: 11px;"><span style="font-family: Menlo;">;</span></span></span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">    [<span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">extensionContext</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">inputItems</span></span></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">enumerateObjectsUsingBlock</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:^(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSExtensionItem</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nonnull</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">extItem</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSUInteger</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">idx,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nonnull</span> <span style="font-size: 11px;"><span style="font-family: Menlo;">stop) {</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">       <br/>
        [item.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">attachments</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">enumerateObjectsUsingBlock</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:^(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSItemProvider</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nonnull</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">itemProvider,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSUInteger</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">idx,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nonnull</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">stop) {<br/>
           <br/>
           </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">if</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">([itemProvider</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">hasItemConformingToTypeIdentifier</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"public.url"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">])<br/>
            {<br/>
                [itemProvider</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">loadItemForTypeIdentifier</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"public.url"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
                                               </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">options</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nil</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
                                     </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">completionHandler</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:^(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">id</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&lt;</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSSecureCoding</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&gt; </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nullable</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">item,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSError</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">error) {<br/>
                                         <br/>
                                         </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">if</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">([(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSObject</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)item</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">isKindOfClass</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">class</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]])<br/>
                                          {<br/>
                                             </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">NSLog</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b">分享的</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">URL = %@"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">, item);<br/>
                                             </span> <b><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSUserDefaults</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>*userDefaults = [[</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>NSUserDefaults</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>alloc</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>]</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>initWithSuiteName</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>:</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b"><b>@"group.cn.vimfung.ShareExtensionDemo"</b></span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;"><b><span style="font-size: 11px;"><span style="font-family: Menlo;">];</span></span></b></span></b></div>
<div><b><span style="font-size: 11px;"><span style="font-family: Menlo;">                                              [userDefaults</span></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>setValue</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>:</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>((</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>NSURL</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>*)item).</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>absoluteString</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>forKey</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b"><b>@"share-url"</b></span><span style="font-size: 11px;"><span style="font-family: Menlo;"><b>];</b></span></span></b></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">                                            </span></span>   <b><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400"><b>用于标记是新的分享</b></span></b></div>
<div><span style="font-family: Menlo;"><span style="font-size: 11px;"><b>                                              [userDefaults <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>setBool</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>:</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2"><b>YES</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>forKey</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>:</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b"><b>@"has-new-share"</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>];</b></span></b></span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">                                          }<br/>
                                         <br/>
                                      }];<br/>
               <br/>
                hasExistsUrl =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">YES</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
                *stop =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">YES</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
            }<br/>
           <br/>
        }];<br/>
       <br/>
       </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">if</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(hasExistsUrl)<br/>
        {<br/>
            *stop =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">YES</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
        }<br/>
       <br/>
    }];<br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//    [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];</span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">}</span></span></div>
</td>
</tr>
</table>
<div><br/></div>
<div><b>2.3.3 做好分享插件的提示操作</b></div>
<div><br/></div>
<div>默认情况下，如果用户点击Post按钮后，分享界面就会消失，用户可以继续对宿主程序进行操作。这些都要靠<span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">NSExtensionContext<span style="font-family: Menlo;">d的</span></span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">completeRequestReturningItems:completionHandler:方法来实现。现在，由于在</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">didSelectPost方法中加入了分享内容的处理，由于获取附件是一个异步过程，那么，就需要做好界面上的提示。否则，分享界面消失后由于没有操作提示，会使用户误以为界面进行卡死的状态，其实是分享内容还没有处理完成。接下来就是优化UI上的提示操作，代码如下：</span></div>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">/**<br/>
 * </span> <span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">点击提交按钮</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400"><br/>
 */</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)didSelectPost<br/>
{<br/>
   </span> <b><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400"><b>加载动画初始化</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b><br/>
   </b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>UIActivityIndicatorView</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>*activityIndicatorView = [[</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>UIActivityIndicatorView</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>alloc</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>]</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>initWithActivityIndicatorStyle</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>:</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>UIActivityIndicatorViewStyleWhiteLarge</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>];<br/>
    activityIndicatorView.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>frame</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>=</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>CGRectMake</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>((</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2"><b>self</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>view</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>frame</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>size</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>width</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>- activityIndicatorView.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>frame</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>size</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>width</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>) /</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8"><b>2</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>,<br/>
                                             (</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2"><b>self</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>view</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>frame</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>size</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>height</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>- activityIndicatorView.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>frame</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>size</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>height</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>) /</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8"><b>2</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>,<br/>
                                             activityIndicatorView.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>frame</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>size</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>width</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>,<br/>
                                             activityIndicatorView.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>frame</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>size</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>height</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>);<br/>
    activityIndicatorView.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>autoresizingMask</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>=</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>UIViewAutoresizingFlexibleTopMargin</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>|</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>UIViewAutoresizingFlexibleLeftMargin</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>|</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>UIViewAutoresizingFlexibleRightMargin</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>|</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>UIViewAutoresizingFlexibleBottomMargin</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>;<br/>
    [</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2"><b>self</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>view</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>addSubview</b></span></b><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>:activityIndicatorView];</b><br/>
   <br/>
   </span> <b><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400"><b>激活加载动画</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b><br/>
    [activityIndicatorView</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>startAnimating</b></span></b><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>];</b><br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__weak</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #4f8187">ShareViewController</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*theController =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__block</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">hasExistsUrl =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">NO</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
    [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">extensionContext</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">inputItems</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">enumerateObjectsUsingBlock</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:^(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSExtensionItem</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nonnull</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">extItem,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSUInteger</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">idx,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nonnull</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">stop) {<br/>
       <br/>
        [extItem.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">attachments</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">enumerateObjectsUsingBlock</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:^(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSItemProvider</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nonnull</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">itemProvider,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSUInteger</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">idx,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nonnull</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">stop) {<br/>
           <br/>
           </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">if</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">([itemProvider</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">hasItemConformingToTypeIdentifier</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"public.url"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">])<br/>
            {<br/>
                [itemProvider</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">loadItemForTypeIdentifier</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"public.url"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
                                               </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">options</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nil</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
                                     </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">completionHandler</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:^(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">id</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&lt;</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSSecureCoding</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&gt; </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nullable</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">item,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSError</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">error) {<br/>
                                         <br/>
                                         </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">if</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">([(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSObject</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)item</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">isKindOfClass</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">class</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]])<br/>
                                          {<br/>
                                             </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">NSLog</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b">分享的</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">URL = %@"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">, item);<br/>
                                             </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSUserDefaults</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*userDefaults = [[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSUserDefaults</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">alloc</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">initWithSuiteName</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"group.cn.vimfung.ShareExtensionDemo"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
                                              [userDefaults</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">setValue</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:((</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)item).</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">absoluteString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">forKey</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"share-url"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];</span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">                                              </span></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">用于标记是新的分享</span></div>
<div><span style="font-family: Menlo;"><span style="font-size: 11px;">                                              [userDefaults <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">setBool</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">YES</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">forKey</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"has-new-share"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];</span></span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">                                             <br/>
                                              <b>[activityIndicatorView</b></span> <b><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">stopAnimating</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>];<br/>
                                              [theController.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>extensionContext</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>completeRequestReturningItems</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>:</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8"><b>@[</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>extItem</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8"><b>]</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>completionHandler</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>:</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2"><b>nil</b></span></b><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>];</b><br/>
                                          }<br/>
                                         <br/>
                                      }];<br/>
               <br/>
                hasExistsUrl =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">YES</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
                *stop =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">YES</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
            }<br/>
           <br/>
        }];<br/>
       <br/>
       </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">if</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(hasExistsUrl)<br/>
        {<br/>
            *stop =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">YES</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
        }<br/>
       <br/>
    }];<br/>
   <br/>
   </span> <b><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">if</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>(!hasExistsUrl)<br/>
    {<br/>
       </b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400"><b>//</b></span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400"><b>直接退出</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b><br/>
        [</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2"><b>self</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>.</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>extensionContext</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>completeRequestReturningItems</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>:</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8"><b>@[]</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>completionHandler</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>:</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2"><b>nil</b></span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;"><b><span style="font-size: 11px;"><span style="font-family: Menlo;">];<br/>
    }</span></span></b></span></b></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">}</span></span></div>
</td>
</tr>
</table>
<div><br/></div>
<div><br/></div>
<div><b><span style="font-size: 18px;">2.4 容器程序获取分享数据</span></b></div>
<div><br/></div>
<div>插件的工作基本上已经全部开发完成了，接下来就是容器程序获取数据并进行操作。下面是容器程序的处理代码：</div>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)applicationDidBecomeActive:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UIApplication</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)application<br/>
{<br/>
   </span> <b><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400"><b>获取共享的</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400"><b>UserDefaults</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b><br/>
   </b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>NSUserDefaults</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>*userDefaults = [[</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa"><b>NSUserDefaults</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>alloc</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>]</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>initWithSuiteName</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>:</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b"><b>@"group.cn.vimfung.ShareExtensionDemo"</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>];<br/>
   </b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2"><b>if</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>([userDefaults</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>boolForKey</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>:</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b"><b>@"has-new-share"</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>])<br/>
    {<br/>
       </b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>NSLog</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>(</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b"><b>@"</b></span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b"><b>新的分享</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b"><b>: %@"</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>, [userDefaults</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>valueForKey</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>:</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b"><b>@"share-url"</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>]);<br/>
       <br/>
       </b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400"><b>//</b></span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400"><b>重置分享标识</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b><br/>
        [userDefaults</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>setBool</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>:</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2"><b>NO</b></span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81"><b>forKey</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><b>:</b></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b"><b>@"has-new-share"</b></span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;"><b><span style="font-size: 11px;"><span style="font-family: Menlo;">];<br/>
    }</span></span></b></span></b></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">}</span></span></div>
</td>
</tr>
</table>
<div><br/></div>
<div>为了方便演示，这里直接在AppDelegate中的<span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">applicationDidBecomeActive:方法中检测是否有新的分享，如果有则通过Log打印链接出来。</span></div>
<div>至此，整个Share Extension开发的过程已经完成。</div>
<div><br/></div>
<div><b><span style="font-size: 18px;">2.5 提审AppStore的注意事项</span></b></div>
<div><br/></div>
<ol>
<li>扩展中的处理不能太长时间阻塞主线程（建议放入线程中处处理），否则可能导致苹果拒绝你的应用。</li>
<li>扩展不能单独提审，必须要跟容器程序一起提交AppStore进行审核。</li>
<li>提审的扩展和容器程序的Build Version要保持一致，否则在上传审核包的时候会提示警告，导致程序无法正常提审。</li>
</ol>
<div><br/></div>
<div><b><span style="font-size: 24px;">3 进阶研究</span></b></div>
<div><br/></div>
<div><b><span style="font-size: 18px;">3.1 对默认分享界面进行扩展</span></b></div>
<div><b><span style="font-size: 18px;"><br/></span></b></div>
<div>在某些情况下，在分享界面中会加入一下其它信息的显示，或者其它的选项供用户操作。如：内容要分享给什么好友、分享内容的可见权限等等。那么，默认的分享界面（ <span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">SLComposeServiceViewController</span>）提供了相关的方法来对其进行扩展。这些方法定义如下：</div>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">#if TARGET_OS_IPHONE<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">/*<br/>
 Configuration Item Support (account pickers, privacy selection, location, etc.)<br/>
 */</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Subclasses should implement this, and return an array of SLComposeSheetConfigurationItem instances, if if needs to display configuration items in the sheet. Defaults to nil.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSArray</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)configurationItems;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Forces a reload of the configuration items table.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// This is typically only necessary for subclasses that determine their configuration items in a deferred manner (for example, in -presentationAnimationDidFinish).</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// You do not need to call this after changing a configuration item property; the base class detects and reacts to that automatically.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)reloadConfigurationItems;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Presents a configuration view controller. Typically called from a configuration item's tapHandler. Only one configuration view controller is allowed at a time.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// The pushed view controller should set preferredContentSize appropriately. SLComposeServiceViewController observes changes to that property and animates sheet size changes as necessary.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)pushConfigurationViewController:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UIViewController</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)viewController;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Dismisses the current configuration view controller.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)popConfigurationViewController;</span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">#endif</span></div>
</td>
</tr>
</table>
<div><br/></div>
<div>下面是方法的说明</div>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSArray</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)configurationItems;</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:49.883449883449885%;">
<div>一个<span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">SLComposeSheetConfigurationItem类型的数组，默认情况下该方法返回一个nil。如果你想增加一项扩展信息，可以通过改写这个方法来增加一个</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">SLComposeSheetConfigurationItem对象来实现。下面会介绍</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">SLComposeSheetConfigurationItem的一些相关信息。</span></div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)reloadConfigurationItems;</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>重新加载配置项列表，该方法会重新触发<span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">configurationItems的调用，并且刷新配置项的变更内容。</span></div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)pushConfigurationViewController:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UIViewController</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)viewController;</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>显示一个配置相关的视图控制器。该方法是结合我们自定义的配置项而设计，当点击某个配置项时需要更详细的选择，则可以使用此方法来现实一个视图控制器，并进行相关的配置。注：每次只允许显示一个配置视图控制器。</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)popConfigurationViewController;</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>关闭一个配置的视图控制器。</div>
</td>
</tr>
</table>
<div><br/></div>
<div>再来看一下<span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">SLComposeSheetConfigurationItem的声明：</span></div>
<div><span style="font-family: Menlo;"><br/></span></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">typedef</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(^SLComposeSheetConfigurationItemTapHandler)(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">);<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Represents a user-configurable option for the compose session.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// For allowing the user to choose which account to post from, what privacy settings to use, etc.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">SOCIAL_CLASS_AVAILABLE</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(NA,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">_0)<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@interface</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">SLComposeSheetConfigurationItem :</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSObject</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Designated initializer</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">instancetype</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)init</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #78492a">NS_DESIGNATED_INITIALIZER</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@property</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nonatomic</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">copy</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*title;</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// The displayed name of the option.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@property</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nonatomic</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">copy</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSString</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*value;</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// The current value/setting of the option.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@property</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nonatomic</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">assign</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">valuePending;</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Default is NO. set to YES to show a progress indicator. Can be used with a value too.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Called on the main queue when the configuration item is tapped.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Your block should not keep a strong reference to either the configuration item, or the SLComposeServiceViewController, otherwise you'll end up with a retain cycle.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@property</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nonatomic</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">copy</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">SLComposeSheetConfigurationItemTapHandler</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">tapHandler;<br/>
<br/></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@end</span></div>
</td>
</tr>
</table>
<div><span style="font-family: Menlo;"><br/></span></div>
<div><span style="font-family: Menlo;">其属性说明如下：</span></div>
<div><span style="font-family: Menlo;"><br/></span></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">title</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:49.883449883449885%;">
<div>配置项标题</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">value</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>当前的配置值。</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">valuePending</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>YES时，显示值位置显示加载动画，NO时，显示配置的值。</div>
</td>
</tr>
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">tapHandler</span></div>
</td>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:50%;">
<div>点击配置项的事件处理</div>
</td>
</tr>
</table>
<div><span style="font-family: Menlo;"><br/></span></div>
<div><br/></div>
<div>下面将通过使用这些方法来扩展UI，使插件增加两个配置项：一个是是否公开分享的配置项，该选项标识一个开关值。另外一个是公开权限设置项，在是否公开分享的开关为开时显示。可以选择分享给所有人还是好友。代码如下所示：</div>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSArray</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)configurationItems {<br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">定义两个配置项，分别记录用户选择是否公开以及公开的权限，然后根据配置的值</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">static</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">isPublic =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">NO</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">static</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSInteger</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">act =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">0</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSMutableArray</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*items = [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSMutableArray</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">array</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">创建是否公开配置项</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">SLComposeSheetConfigurationItem</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*item = [[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">SLComposeSheetConfigurationItem</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">alloc</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">init</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
    item.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">title</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b">是否公开</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
    item.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">value</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">= isPublic ?</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b">是</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">"</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b">否</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__weak</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #4f8187">ShareViewController</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*theController =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__weak</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">SLComposeSheetConfigurationItem</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*theItem = item;<br/>
    item.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">tapHandler</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">= ^{<br/>
     <br/>
        isPublic = !isPublic;<br/>
        theItem.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">value</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">= isPublic ?</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b">是</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">"</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b">否</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
       <br/>
       <br/>
        [theController</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">reloadConfigurationItems</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
    };<br/>
   <br/>
    [items</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">addObject</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:item];<br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">if</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(isPublic)<br/>
    {<br/>
       </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">如果公开标识为</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">YES</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">，则创建公开权限配置项</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
       </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">SLComposeSheetConfigurationItem</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*actItem = [[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">SLComposeSheetConfigurationItem</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">alloc</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">init</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
<br/>
        actItem.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">title</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b">公开权限</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
       <br/>
       </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">switch</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(act)<br/>
        {<br/>
           </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">case</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">0</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:<br/>
                actItem.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">value</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b">所有人</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
               </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">break</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
           </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">case</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">1</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:<br/>
                actItem.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">value</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b">好友</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
               </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">break</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
           </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">default</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:<br/>
               </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">break</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
        }<br/>
       <br/>
        actItem.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">tapHandler</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">= ^{<br/>
         <br/>
           </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">设置分享权限时弹出选择界面</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
           </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #4f8187">ShareActViewController</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*actVC = [[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #4f8187">ShareActViewController</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">alloc</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">init</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
            [theController</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">pushConfigurationViewController</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:actVC];<br/>
           <br/>
            [actVC</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #31595d">onSelected</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:^(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSIndexPath</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*indexPath) {<br/>
              <br/>
               </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">当选择完成时退出选择界面并刷新配置项。</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
                act = indexPath.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">row</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
                [theController</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">popConfigurationViewController</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
                [theController</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">reloadConfigurationItems</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
               <br/>
            }];<br/>
           <br/>
        };<br/>
       <br/>
        [items</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">addObject</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:actItem];<br/>
    }<br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">return</span> <span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;"><span style="font-size: 11px;"><span style="font-family: Menlo;">items;</span></span></span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">}</span></span></div>
</td>
</tr>
</table>
<div><br/></div>
<div>ShareActViewController实现：</div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@interface</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #4f8187">ShareActViewController</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">() &lt;</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UITableViewDelegate</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UITableViewDataSource</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&gt;<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@property</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nonatomic</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">strong</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(^selectedHandler) ();<br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@end</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
<br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@implementation</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">ShareActViewController<br/>
<br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)viewDidLoad<br/>
{<br/>
    [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">super</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">viewDidLoad</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UITableView</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*tableView = [[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UITableView</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">alloc</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">initWithFrame</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">view</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">bounds</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
    tableView.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">backgroundColor</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">= [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UIColor</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">clearColor</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
    tableView.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">autoresizingMask</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">UIViewAutoresizingFlexibleWidth</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">|</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">UIViewAutoresizingFlexibleHeight</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
    tableView.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">dataSource</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
    tableView.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">delegate</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
    [tableView</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">registerClass</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UITableViewCell</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">class</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">forCellReuseIdentifier</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"Cell"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
    [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">view</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">addSubview</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:tableView];<br/>
}<br/>
<br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)onSelected:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(^)(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSIndexPath</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*indexPath))handler<br/>
{<br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #4f8187">selectedHandler</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">= handler;<br/>
}<br/>
<br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSInteger</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)tableView:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UITableView</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)tableView numberOfRowsInSection:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSInteger</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)section<br/>
{<br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">return</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">2</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
}<br/>
<br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UITableViewCell</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)tableView:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UITableView</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)tableView cellForRowAtIndexPath:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSIndexPath</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)indexPath<br/>
{<br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UITableViewCell</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*cell = [tableView</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">dequeueReusableCellWithIdentifier</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"Cell"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
    cell.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">backgroundColor</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">= [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UIColor</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">clearColor</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">switch</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(indexPath.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">row</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)<br/>
    {<br/>
       </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">case</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">0</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:<br/>
            cell.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">textLabel</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">text</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b">所有人</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
           </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">break</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
       </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">case</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">1</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:<br/>
            cell.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">textLabel</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">text</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b">好友</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
           </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">break</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
       </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">default</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:<br/>
           </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">break</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
    }<br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">return</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">cell;<br/>
}<br/>
<br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)tableView:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UITableView</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)tableView didSelectRowAtIndexPath:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSIndexPath</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)indexPath<br/>
{<br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">if</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #4f8187">selectedHandler</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)<br/>
    {<br/>
       </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #4f8187">selectedHandler</span> <span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;"><span style="font-size: 11px;"><span style="font-family: Menlo;">(indexPath);<br/>
    }</span></span></span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">}</span></span></div>
</td>
</tr>
</table>
<div><br/></div>
<div>在分享插件界面中重写了<span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">configurationItems方法，然后定义了两个配置项属性，分别是是否公开标识</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">isPublic和公开权限</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">act。然后创建是否公开的</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">SLComposeSheetConfigurationItem配置项和根据isPublic的值来判断是否创建公开权限配置项。其中是否公开配置点击时会变更isPublic的值，从而达到显示或隐藏公开权限配置。而公开权限配置的点击则弹出一个选择的TableView，用于选择给定的值然后返回到分享界面。</span></div>
<div><br/></div>
<div><b><span style="font-size: 18px;">3.2 替换Share Extension中的默认分享界面</span></b></div>
<div><b><span style="font-size: 18px;"><br/></span></b></div>
<div>如果通过扩展<span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">SLComposeServiceViewController还不能满足需求的情况下，这时候就需要自己设计一个分享视图控制器来替换默认的</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">SLComposeServiceViewController。</span></div>
<div><br/></div>
<ol>
<li>首先，创建一个自定义视图控制器，如：CustomShareViewController。</li>
<li>然后打开扩展的Info.plist文件，删除NSExtensionMainStoryboard属性并增加一项<span style="font-size: 13px;"><font style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-family: Helvetica; -webkit-font-kerning: none; font-variant-ligatures: common-ligatures; color: rgb(0, 0, 0); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0);" face="Helvetica" color="#000000">NSExtensionPrincipalClass属性并指向</font></span>CustomShareViewController（注：这里没有使用Storyboard所以要删除该属性），如图：<img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/B67927D4-4BE0-48A9-BD85-B87F0EA564C8.png" height="100" width="520"/></li>
<li>接下来根据实际的需要来设计分享视图的展示与交互形式。</li>
<li>然后调用CustomShareViewController的<span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">extensionContext属性来控制扩展的提交与取消等操作（注：由于扩展中导入了关于ExtensionContext的UIViewController类目，因此，每个ViewController都带有</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">extensionContext属性</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;">）。</span></li>
</ol>
<div><br/></div>
<div>为了演示的简单性，下面的代码会通过extensionContext获取到url后，给到自定义分享视图的Label中显示，同时也提供一个提交和取消按钮，用于用户对分享内容的操作。代码如下：</div>
<div><br/></div>
<table style="-evernote-table:true;border-collapse:collapse;table-layout:fixed;margin-left:0px;width:100%;">
<tr>
<td style="border-style:solid;border-width:1px;border-color:rgb(219,219,219);padding:10px;margin:0px;width:99.88344988344988%;">
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)viewDidLoad<br/>
{<br/>
    [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">super</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">viewDidLoad</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">// Do any additional setup after loading the view.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">定义一个容器视图来存放分享内容和两个操作按钮</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UIView</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*container = [[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UIView</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">alloc</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">initWithFrame</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">CGRectMake</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">((</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">view</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">size</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">width</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">-</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">300</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">) /</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">2</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">, (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">view</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">size</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">height</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">-</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">175</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">) /</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">2</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">300</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">175</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)];<br/>
    container.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">layer</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">cornerRadius</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">7</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
    container.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">layer</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">borderColor</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">= [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UIColor</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">lightGrayColor</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">].</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">CGColor</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
    container.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">layer</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">borderWidth</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">1</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
    container.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">layer</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">masksToBounds</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">YES</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
    container.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">backgroundColor</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">= [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UIColor</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">whiteColor</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
    container.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">autoresizingMask</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">UIViewAutoresizingFlexibleTopMargin</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">|</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">UIViewAutoresizingFlexibleLeftMargin</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">|</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">UIViewAutoresizingFlexibleRightMargin</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">|</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">UIViewAutoresizingFlexibleBottomMargin</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
    [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">view</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">addSubview</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:container];<br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">定义</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">Post</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">和</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">Cancel</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">按钮</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UIButton</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*cancelBtn = [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UIButton</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">buttonWithType</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">UIButtonTypeSystem</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
    [cancelBtn</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">setTitle</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"Cancel"</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">forState</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">UIControlStateNormal</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
    cancelBtn.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">CGRectMake</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">65</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">40</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">);<br/>
    [cancelBtn</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">addTarget</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">action</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@selector</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(cancelBtnClickHandler:)</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">forControlEvents</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">UIControlEventTouchUpInside</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
    [container</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">addSubview</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:cancelBtn];<br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UIButton</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*postBtn = [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UIButton</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">buttonWithType</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">UIButtonTypeSystem</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
    [postBtn</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">setTitle</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"Post"</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">forState</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">UIControlStateNormal</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
    postBtn.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">CGRectMake</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(container.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">size</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">width</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">-</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">-</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">65</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">65</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">40</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">);<br/>
    [postBtn</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">addTarget</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">action</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">@selector</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(postBtnClickHandler:)</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">forControlEvents</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">UIControlEventTouchUpInside</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
    [container</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">addSubview</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:postBtn];<br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">定义一个分享链接标签</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UILabel</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*label = [[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">UILabel</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">alloc</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">initWithFrame</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">CGRectMake</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,<br/>
                                                               cancelBtn.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">origin</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">y</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">+ cancelBtn.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">size</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">height</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">+</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">8</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,<br/>
                                                               container.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">size</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">width</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">-</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">16</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,<br/>
                                                               container.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">size</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">height</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">-</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">16</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">- cancelBtn.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">origin</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">y</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">- cancelBtn.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">size</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">height</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)];<br/>
    label.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">numberOfLines</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">0</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
    label.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">textAlignment</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">=</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">NSTextAlignmentCenter</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
    [container</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">addSubview</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:label];<br/>
   <br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">获取分享链接</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">__block</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">hasGetUrl =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">NO</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
    [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">extensionContext</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">inputItems</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">enumerateObjectsUsingBlock</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:^(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSExtensionItem</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">* </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nonnull</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">obj,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSUInteger</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">idx,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nonnull</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">stop) {<br/>
      <br/>
        [obj.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">attachments</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">enumerateObjectsUsingBlock</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:^(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSItemProvider</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">* </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nonnull</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">itemProvider,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSUInteger</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">idx,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">BOOL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nonnull</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">stop) {<br/>
           <br/>
           </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">if</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">([itemProvider</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">hasItemConformingToTypeIdentifier</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"public.url"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">])<br/>
            {<br/>
                [itemProvider</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">loadItemForTypeIdentifier</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"public.url"</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">options</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nil</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">completionHandler</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:^(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">id</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&lt;</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSSecureCoding</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">&gt; </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Nullable</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">item,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSError</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">_Null_unspecified</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">error) {<br/>
                  <br/>
                   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">if</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">([(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSObject</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)item</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">isKindOfClass</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">class</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]])<br/>
                    {<br/>
                       </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">dispatch_async</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">dispatch_get_main_queue</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(), ^{<br/>
                          <br/>
                            label.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">text</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">= ((</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSURL</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">*)item).</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">absoluteString</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
                           <br/>
                        });<br/>
                    }<br/>
                   <br/>
                }];<br/>
               <br/>
                hasGetUrl =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">YES</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
                *stop =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">YES</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
            }<br/>
           <br/>
            *stop = hasGetUrl;<br/>
           <br/>
        }];<br/>
       <br/>
    }];<br/>
}<br/>
<br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)cancelBtnClickHandler:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">id</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)sender</span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">{</span></span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">    </span></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//取消分享</span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">    [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">extensionContext</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">cancelRequestWithError</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:[</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">NSError</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">errorWithDomain</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #d12f1b">@"CustomShareError"</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">code</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">NSUserCancelledError</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">userInfo</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nil</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">]];<br/>
}<br/>
<br/>
- (</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">void</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)postBtnClickHandler:(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">id</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">)sender<br/>
{<br/>
   </span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #008400">//</span><span style="font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400">执行分享内容处理</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/>
    [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">self</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">.</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">extensionContext</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">completeRequestReturningItems</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #272ad8">@[]</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">completionHandler</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">:</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #bb2ca2">nil</span><span style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-variant-ligatures: no-common-ligatures;"><span style="font-size: 11px;"><span style="font-family: Menlo;">];</span></span></span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">}</span></span></div>
</td>
</tr>
</table>
<div><br/></div>
<div><font face="Helvetica"><span style="font-size: 13px;">效果如下图所示：</span></font></div>
<div><span style="font-size: 13px;"><span style="font-family: Helvetica;"><br/></span></span></div>
<div><img src="iOS%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5(%E4%B8%80)%20-%20Share%20Extension.resources/58084D8A-8B8B-47C2-BF93-CC9B68DDA2C6.png" height="730" width="408"/></div>
<div><br/></div>
<div><br/></div>
</body></html>